#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@Author          : ricsy
@File            : icon_interactive.py.py
@Create Time     : 2025/6/18 03:24
@Last Modified   :
@Description     : 图标指令配置生成器
"""
from ipywidgets import widgets

from extensions.common import deep_merge
from extensions.interactive.base_interactive import BaseInteractive
from extensions.sphinx_icon import IconDirective


class IconInteractive(BaseInteractive):
    DIRECTIVE_NAME = "icon"
    CLASS_PREFIX = "icon-preview"

    DEFAULT_OPTIONS = deep_merge(
        IconDirective.DEFAULT_OPTIONS,
        {
            "logobrand": {"value": "7"},
            "title": {"value": "你好，世界！"},
            "tooltippos": {"value": "bottom"},
        },
    )

    CONTROL_LAYOUT_CONFIG = {
        "logobg": {"width": "30%", "margin": "2px 0.5rem 2px 2px"},
        "logocolor": {"width": "30%", "margin": "2px 0.5rem 2px 2px"},
        "titlecolor": {"width": "30%"},
        "size": {"width": "30%", "margin": "2px 0.5rem 2px 2px"},
        "animation": {"width": "30%"},
        "logosize": {"width": "100%"},
        "radius": {"width": "100%"},
        "logobrand": {"width": "100%"},
        "title": {"width": "100%"},
        "link": {"width": "100%"},
        "tooltip": {"width": "100%"},
        "tooltippos": {"width": "30%", "margin": "2px 0.5rem 2px 2px"},
        "shadow": {"width": "30%"},
    }

    def build_main_layout(self):
        """图标专用布局"""
        return widgets.VBox(
            [
                widgets.HBox(
                    [
                        self.controls["logobg"].widget,
                        self.controls["logocolor"].widget,
                        self.controls["titlecolor"].widget,
                    ],
                    layout=widgets.Layout(width="100%", grid_gap="0.5rem"),
                ),
                widgets.HBox(
                    [self.controls["size"].widget, self.controls["animation"].widget],
                    layout=widgets.Layout(width="100%", grid_gap="0.5rem"),
                ),
                *[
                    widgets.HBox(
                        [self.controls[name].widget],
                        layout=widgets.Layout(width="100%", grid_gap="0.5rem"),
                    )
                    for name in [
                        "logosize",
                        "radius",
                        "logobrand",
                        "title",
                        "link",
                        "tooltip",
                    ]
                ],
                widgets.HBox(
                    [
                        self.controls["tooltippos"].widget,
                        self.controls["shadow"].widget,
                    ],
                    layout=widgets.Layout(width="100%", grid_gap="0.5rem"),
                ),
                widgets.HBox(
                    [self.generate_btn, self.reset_btn],
                    layout=widgets.Layout(
                        width="100%", justify_content="flex-end", grid_gap="1rem"
                    ),
                ).add_class("preview-btn-group"),
                self.config_output,
            ],
            layout=widgets.Layout(width="100%", grid_gap="0.5rem"),
        )


if __name__ == "__main__":
    icon_interactive = IconInteractive()
    icon_interactive.run()
